<%@page import="com.interfaces.SysConfigController"%>
<%@ page import="com.interfaces.TravelAgentController" %>
<%@ page import="com.core.sysDict.SysDictJsp" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>参数管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    <%
    	String path = request.getContextPath();
            path = "/".equals(path)?"":path;
            request.setAttribute("path", path);
            String sysDictJson=SysDictJsp.getSysDictJson(session);
    %>
    <script type="text/javascript">
        var path = "${path}";
    </script>

    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="${path}/public/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="${path}/public/font-awesome-4.7.0/css/font-awesome.min.css">
    <!--datatable-editor  -->
     <link rel="stylesheet" href="${path}/js/datatable-editor/1.6.1/css/editor.dataTables.min.css">
     <!-- Select2 -->
  	<link rel="stylesheet" href="${path}/public/adminlte/plugins/select2/select2.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="${path}/public/ionicons/ionicons.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
          page. However, you can choose any other skin. Make sure you
          apply the skin class to the body tag so the changes take effect.
    -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/skins/_all-skins.min.css">

    <link rel="stylesheet" href="${path}/css/common.css">
	<link rel="stylesheet" href="${path}/js/datatable-editor/1.6.1/css/select.dataTables.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript" src="${path}/js/json2.js"></script>
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS         | skin-blue                               |
|               | skin-black                              |
|               | skin-purple                             |
|               | skin-yellow                             |
|               | skin-red                                |
|               | skin-green                              |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed                                   |
|               | layout-boxed                            |
|               | layout-top-nav                          |
|               | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->
<body >
<div class="container">
<div class="box box-primary">
     	 <h3 class="box-title">参数管理</h3>
         <div class="box-body">
            <table id="dg1" class="table table-bordered table-hover">
            </table>
         </div>
         <!-- /.box-body -->
     </div>   
<!-- ./wrapper -->
</div>
<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 2.2.3 -->
<script src="${path}/public/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${path}/public/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="${path}/js/datatable-editor/1.6.1/js/jquery.dataTables.min.js"></script>
<!--inLine  -->
<script src="${path}/public/inLine/dataTables.buttons.min.js"></script>
<script src="${path}/js/datatable-editor/1.6.1/js/dataTables.editor.min.js"></script>
<script src="${path}/public/inLine/dataTables.select.min.js"></script>
<!-- DataTables -->
<script src="${path}/public/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- Select2 -->
<script src="${path}/public/adminlte/plugins/select2/select2.full.min.js"></script>
<!-- SlimScroll -->
<script src="${path}/public/adminlte/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="${path}/public/adminlte/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="${path}/public/adminlte/dist/js/app.min.js"></script>
<!-- 判空和输入检测 -->
<script src="${path}/js/validata.js"></script>

<script src="${path}/js/sysDict.js"></script>
<!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. Slimscroll is required when using the
     fixed layout. -->
<!-- page script -->
<script>
    var table;
    editorForCreate = new $.fn.dataTable.Editor( {
    	idSrc:  'id',
    	i18n : {  
        create : {  
            title : "新增参数信息",  
            submit : "添加"  
        }  
    },  
	ajax: function ( method, url, data, success, error ) {  
                    var result={};  
                    for(var i in data.data){  
                        var result=data.data[i];  
                        result.DT_RowId=i;  
                        result.action=data.action;  
                    }  
                    $.ajax( {  
                        type: "post",  
                        "url":"${path}<%=SysConfigController.URL_ADD%>",
                        data: result,  
                        dataType: "json",  
                        success: function (json) {
                        if(json.returnCode=="0"){
                        	success(json);
                        	table.ajax.reload();
                        	var url= window.location.search;
                			var arr = url.split('&');
                        	parent.refresh(arr[arr.length-1]);   
                        }else{
                        success(json);
                        alert("不成功!");
                        }  
                        }  
                    } );  
                },   
        table: "#dg1",
        fields: [ {
                label: "key:",
                name: "key_no"
            }, 
            {
                label: "value",
                name: "key_value"
            },
            {
                label: "说明/备注",
                name: "comment"
            },
        ],
    });
    editorForEdit = new $.fn.dataTable.Editor({  
        idSrc:'id',
        i18n : {  
            edit : {  
                title : "修改参数信息",  
                submit : "修改"  
            }  
        },  
        ajax: function ( method, url, data, success, error ) {  
                    var result={};  
                    for(var i in data.data){  
                        var result=data.data[i];  
                        result.DT_RowId=i;  
                        result.action=data.action;  
                        console.log(result);  
                    }  
                    $.ajax( {  
                        type: "post",  
                        "url":"${path}<%=SysConfigController.URL_UPDATE%>",
                        data: result,  
                        dataType: "json",  
                        success: function (json) {
                        console.log(json);
                        if(json.returnCode=="0"){
                        	success(json);
                        	table.ajax.reload();
                        	var url= window.location.search;
                			var arr = url.split('&');
                        	parent.refresh(arr[arr.length-1]);  
                        }else{
                        success(json);
                        alert("不成功!");
                        }  
                        }  
                    } );  
                },    
        table: "#dg1",
        fields: [ {
                label: "id:",
                name: "id"
            },{
                label: "key:",
                name: "key_no"
            }, 
            {
                label: "value:",
                name: "key_value"
            },{
                label: "说明/备注",
                name: "comment"
            },
        ],
    });
    editorForDel = new $.fn.dataTable.Editor({  
        idSrc:'id',
        i18n : {  
            remove: {
                button: "删除",
                title:  "删除",
                submit: "确定",
                confirm: {
                    _: "确定要删除这 %d 条记录?",
                    1: "确定要删除这 1 条记录?"
                }
            }  
        },  
        ajax: function ( method, url, data, success, error ) {  
                    var result={};  
                    for(var i in data.data){  
                        var result=data.data[i];  
                        result.DT_RowId=i;  
                        result.action=data.action;  
                        console.log(result);  
                    }  
                    $.ajax( {  
                        type: "post",  
                        "url":"${path}<%=SysConfigController.URL_DELETE%>",
                        data: result,  
                        dataType: "json",  
                        success: function (json) {
                        console.log(json);
                        if(json.returnCode=="0"){
                        	success(json);
                        	table.ajax.reload();  
                        }else{
                        success(json);
                        alert("不成功!");
                        }  
                        }  
                    } );  
                },    
        table: "#dg1",
        fields: [ {
                label: "id:",
                name: "id"
            }, {
                label: "key:",
                name: "key_no"
            }, 
            {
                label: "value:",
                name: "key_value"
            },{
                label: "说明/备注",
                name: "comment"
            },
        ],
    });
    table =$('#dg1').DataTable( {
    	select: true,
    	searching : false,
    	paginate : false,  
        dom: "Bfrtip",
        "ajax":{
            	 "url":"${path}<%=SysConfigController.URL_DB_SEARCH%>",
            	 "type":"post",
            	 "dataType":"JSON",
            },
        columns: [
            {
                data: null,
                defaultContent: '',
                className:'select-checkbox',
            },
            { data: "id","title":"序号","visible": false,},
            { data: "key_no","title":"key"},
            { data: "key_value","title":"value" },
            { data: "comment","title":"说明/备注",},
        ],
        order: [ 1, 'asc' ],
        select: {
            style:'os',
            selector: 'td:first-child',
        },
        buttons: [
            { extend: "create", editor: editorForCreate,text:'新增'},
            { extend: "edit", editor: editorForEdit,text:'编辑'},
            { extend: "remove", editor: editorForDel,text:'删除' }
        ],
        language: {
            processing:     "Traitement en cours...",
            search:         "Rechercher&nbsp;:",
            lengthMenu:     " ",
            info:           " ",
            infoEmpty:      " ",
            infoFiltered:   " ",
            infoPostFix:    "",
            loadingRecords: "查询中...",
            zeroRecords:    "没有找到数据",
            emptyTable:     "暂时没有数据",
            }
    } );
    table.select();
    table.buttons().container().appendTo("#buttons");
    editorForEdit.hide('id');
$(function () {
     });
</script>
</body>
</html>
